package CtrlLayer;
import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;

/**
 * CtrlCustomer.java
 * @author Brian Lassen
 * @version 20. Marts 2012
 */
public class CtrlCustomer 
{

	    public CtrlCustomer() {}
	    
	    public static ArrayList<Customer> findAllCustomer()
	    {
	      IFDBCustomer dbCust = new DBCustomer();
	      ArrayList<Customer> allCust = new ArrayList<Customer>();
	      allCust = dbCust.getAllCustomer(false);
	      return allCust;
	    }
	    
	    public static Customer findById(int id)
	    {
	        IFDBCustomer dbCust = new DBCustomer();
	        return dbCust.searchCustomerId(id, true);
	    }
	    
	    public static Customer findByFname(String fname)
	    {
	        IFDBCustomer dbCust = new DBCustomer();
	        return dbCust.searchCustomerFname(fname, true);
	    }
	     
	    public static Customer findByLname(String lname)
	    {
	        IFDBCustomer dbCust = new DBCustomer();
	        return dbCust.searchCustomerLname(lname, true);
	    }
	    
	    public static Customer findByAddress(String address)
	    {
	        IFDBCustomer dbCust = new DBCustomer();
	        return dbCust.searchCustomerAddress(address, true);
	    }
	    
	    public static Customer findByPhone(int phone)
	    {
	        IFDBCustomer dbCust = new DBCustomer();
	        return dbCust.searchCustomerPhone(phone, true);
	    }
	      
	      public static int updateCust(int id, String fname, String lname, String address, int zipcode, String phone)
	      {
	          IFDBCustomer  dbCust = new DBCustomer ();
	          Customer cust = new Customer ();
	          cust.setId(id);
	          cust.setFname(fname);
	          cust.setLname(lname);
	          cust.setAddress(address);
	          cust.setZipcode(zipcode);
	          cust.setPhone(phone);
	          return dbCust.updateCustomer(cust);
	      }
	      
	      public static void insertNew(String fname, String lname, String address, int zipcode, String phone)
	      {
	           IFDBCustomer dbCust = new DBCustomer();
	           Customer custObj = new Customer();
	           custObj.setFname(fname);
	           custObj.setLname(lname);
	           custObj.setAddress(address);
	           custObj.setZipcode(zipcode);
	           custObj.setPhone(phone);
	           dbCust.insertCustomer(custObj);
	      }
	      
	      public static void deleteCust(int id)
	      {
	    	  IFDBCustomer dbCust = new DBCustomer();
	    	  dbCust.delete(id);
	      }
	    
	}

